// CViewSap.cpp : implementation file
//

#include "stdafx.h"
#include "PanImage.h"
#include "ViewSap.h"

#include "MainFrm.h"

#include "DD_AnalyCfg.h"
#include "DDErrorDefine.h"
#include "MyDefineHeader.h"

/////////////////////////////////////////////////////////////////////////////
// CViewSap

IMPLEMENT_DYNCREATE(CViewSap, CMyFormView)

CViewSap::CViewSap()
	: CMyFormView()
{
	//{{AFX_DATA_INIT(CViewSap)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

}

CViewSap::~CViewSap()
{
}

void CViewSap::DoDataExchange(CDataExchange* pDX)
{
	CMyFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CViewSap)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CViewSap, CMyFormView)
	//{{AFX_MSG_MAP(CViewSap)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewSap diagnostics

#ifdef _DEBUG
void CViewSap::AssertValid() const
{
	CMyFormView::AssertValid();
}

void CViewSap::Dump(CDumpContext& dc) const
{
	CMyFormView::Dump(dc);
}
#endif //_DEBUG

void CViewSap::Initialize()
{
	m_pRuler = &(g.MainWnd->m_AnalyRulers[eAnalyWindow_Sap]);
	s.ImgAnaly.SetHwnd( eAnalyWindow_Sap,m_hWnd );
	m_bInit = true ;
}



/////////////////////////////////////////////////////////////////////////////
// CViewSap message handlers

void CViewSap::OnDraw(CDC* /*pDC*/)
{
	// TODO: Add your specialized code here and/or call the base class
	if( !m_bInit )
	{
		return;
	}

	DDOnDraw();
}

void CViewSap::DDOnDraw()
{
	POINT tScrollPos     = (POINT)GetScrollPosition();

	zkImgDraw xImgDraw;
	xImgDraw.nScrollx    = tScrollPos.x;
	xImgDraw.nScrolly    = tScrollPos.y;
	xImgDraw.fZoomFactor = m_fZoomFactor;

	s.ImgAnaly.Draw(eAnalyWindow_Sap,&xImgDraw);

}





int CViewSap::CB_OnDrawMarkFun(HDC hDc,int nWidth,int nHeight,DWORD dwDispType,void *pContext)
{
	CViewSap *pView = (CViewSap*)pContext;
	return pView->DXOnDraw(hDc,nWidth,nHeight,dwDispType);
}




void CViewSap::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CPoint Pt = point;
	GetImageXY(Pt);

	if( IsInside( Pt.x,Pt.y ) )
	{
		
	}

	CMyFormView::OnMouseMove(nFlags, point);
}
void CViewSap::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CPoint Pt = point;
	GetImageXY( Pt );
	if( IsInside( Pt.x,Pt.y ) )
	{
		
	}

	SetCapture(); 

	CMyFormView::OnLButtonDown(nFlags, point);
}

void CViewSap::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CPoint Pt = point;
	GetImageXY(Pt);

	if( IsInside( Pt.x,Pt.y ) )
	{	
		
	}


	ReleaseCapture();

	CMyFormView::OnLButtonUp(nFlags, point);
}
void CViewSap::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	g.MainWnd->PostMessage(WM_USER_ZoomAnalyView,eAnalyWindow_Sap,0);
	CMyFormView::OnLButtonDblClk(nFlags, point);
}
void CViewSap::ZoomOut()
{
	m_fZoomFactor *= MouseWheelZoomRate;
	InvalidateView();
	g.ViewmAnaly[eAnalyWindow_Ref]->InvalidateView(m_fZoomFactor);
	g.ViewmAnaly[eAnalyWindow_Adj]->InvalidateView(m_fZoomFactor);
	g.ViewmAnaly[eAnalyWindow_Sub]->InvalidateView(m_fZoomFactor);
}

void CViewSap::ZoomIn()
{
	m_fZoomFactor /= MouseWheelZoomRate;
	InvalidateView();
	g.ViewmAnaly[eAnalyWindow_Ref]->InvalidateView(m_fZoomFactor);
	g.ViewmAnaly[eAnalyWindow_Adj]->InvalidateView(m_fZoomFactor);
	g.ViewmAnaly[eAnalyWindow_Sub]->InvalidateView(m_fZoomFactor);

}


int CViewSap::DXOnDraw(HDC hDc,int nWidth,int nHeight,DWORD dwDispType)
{
	return 0;
}

